/*
 * $Id: client.prg 2011-12-28 17:26 riztan $
 */

/*
 *
 * Copyright 2011 Riztan Gutierrez <riztan / at / gmail.com>
 *
 */

/*
 * Convierte un Valor en Cadena de Texto que puede ser 
 * reconvertido mediante hb_Deserialize()
 */
#include "common.ch"

 
function Value2Remote(uData)

   local cText:="", cType
      
   cType := ValType( uData )
      
      switch cType 
      case "O"
           cText = hb_Serialize('"obj_'+uData:ClassName()+'"')
           exit      
      case "B"
           cText = hb_Serialize("_codeblock_")

      case "P"
           cText = hb_Serialize("_pointer_")

      otherwise
           cText = hb_Serialize( udata )
           exit
      endswitch
      
return cText



/*
 * Convierte un Array en Cadena de Texto que puede ser 
 * reconvertida mediante macrosustitucion &
 */
function Array2CSV(aData)

   local cText
   local uItem
   
   if !hb_IsArray(aData) ; return uValToChar( aData ) ; endif
   
   cText :="{"
   
   for each uItem in aData

      cText += uValToChar(uItem)
      cText += ","
   
   next
   
   cText := left(cText,LEN(cText)-1)+"}"
   
return cText


/* Convierte Un Valor a Cadena */
/* Source from hbsocket of Daniel Garcia-Gil. */
function uValToChar( uVal )

   local cType := ValType( uVal )

   do case
      case cType == "C" .or. cType == "M" .or. cType == "D"
           return ValToPrg(uVal)

      case cType == "T"
           return If( Year( uVal ) == 0, HB_TToC( uVal, '', Set( _SET_TIMEFORMAT ) ), HB_TToC( uVal ) )

      case cType == "L"
           return If( uVal, ".T.", ".F." )

      case cType == "N"
           return AllTrim( Str( uVal ) )

      case cType == "B"
           return "{|| ... }"

      case cType == "A"
           return Array2CSV( uVal )   //"{...}"

      case cType == "O"
           return If( __ObjHasData( uVal, "cClassName" ), uVal:cClassName, uVal:ClassName() )

      case cType == "H"
           return ValToPrg( uVal )    //"{=>}"

      case cType == "P"
           return "0x" + hb_NumToHex( uVal )

      otherwise

           return ""
   endcase

return nil

